package chatserver.model;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;

import androidchat.com.common.Message;
import androidchat.com.common.MessageType;

public class ClientConnection extends Thread {
	Socket socket;

	public ClientConnection(Socket socket) {
		this.socket = socket;
	}

	public void run() {
		while (true) {
			Message packet = new Message();
			try {
				ObjectInputStream objectInputStream = new ObjectInputStream(
						socket.getInputStream());
				ObjectOutputStream objectOutputStream = new ObjectOutputStream(
						socket.getOutputStream());
				packet = (Message) objectInputStream.readObject();
				
				new ClientOperation(packet);
				System.out.println("content is"+packet.getContent());
				System.out.println(packet.getType());
				objectOutputStream.writeObject(packet);

			} catch (IOException | ClassNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

}
